<!doctype html>
<html class="no-js">
  <head><meta charset="utf-8"/>
    <meta name="viewport" content="width=device-width,initial-scale=1"/><link rel="index" title="Index" href="../genindex.html" /><link rel="search" title="Search" href="../search.html" /><link rel="next" title="CONFIG dictionary" href="config.html" /><link rel="prev" title="CLI flags and configuration" href="configuration.html" />

    <link rel="shortcut icon" href="../_static/icon.png"/><meta name="generator" content="sphinx-3.4.3, furo 2020.12.30.beta24"/>
        <title>Example Scenes - manim documentation</title>
      <link rel="stylesheet" href="../_static/styles/furo.css?digest=33d2fc4f3f180ec1ffc6524e273e21d7d58cbe49">
    <link rel="stylesheet" href="../_static/pygments.css">
    <link media="(prefers-color-scheme: dark)" rel="stylesheet" href="../_static/pygments_dark.css">
    


<style>
  :root {
    --color-code-background: #f8f8f8;
  --color-code-foreground: black;
  
  }
  @media (prefers-color-scheme: dark) {
    :root {
      --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  
    }
  }

  /* For allowing end-user-specific overrides */
  .override-light {
    --color-code-background: #f8f8f8;
  --color-code-foreground: black;
  
  }
  .override-dark {
    --color-code-background: #202020;
  --color-code-foreground: #d0d0d0;
  
  }
</style><link rel="stylesheet" type="text/css" href="../_static/copybutton.css" />
    <link rel="stylesheet" type="text/css" href="../_static/custom.css" />
    <link rel="stylesheet" type="text/css" href="../_static/colors.css" />
    <link rel="stylesheet" href="../_static/styles/furo-extensions.css?digest=26485485040e7aaf717c13fd0188a5ad2c2deb60">
    <script id="documentation_options" data-url_root="../" src="../_static/documentation_options.js"></script>
    <script defer="defer" src="../_static/jquery.js"></script>
    <script defer="defer" src="../_static/underscore.js"></script>
    <script defer="defer" src="../_static/doctools.js"></script>
    <script defer="defer" src="../_static/clipboard.min.js"></script>
    <script defer="defer" src="../_static/copybutton.js"></script>
    <script defer src="../_static/scripts/main.js?digest=e931d09b2a40c1bb82b542effe772014573baf67"></script></head>
  <body dir="">
    
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  <symbol id="svg-toc" viewBox="0 0 24 24">
    <title>Contents</title>
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
      stroke-width="1.5" stroke="currentColor" stroke-linecap="round" stroke-linejoin="round">
      <path stroke="none" d="M0 0h24v24H0z"/>
      <line x1="4" y1="6" x2="20" y2="6" />
      <line x1="10" y1="12" x2="20" y2="12" />
      <line x1="6" y1="18" x2="20" y2="18" />
    </svg>
  </symbol>
  <symbol id="svg-menu" viewBox="0 0 24 24">
    <title>Menu</title>
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
      stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
      class="feather feather-menu">
      <line x1="3" y1="12" x2="21" y2="12"></line>
      <line x1="3" y1="6" x2="21" y2="6"></line>
      <line x1="3" y1="18" x2="21" y2="18"></line>
    </svg>
  </symbol>
  <symbol id="svg-arrow-right" viewBox="0 0 24 24">
    <title>Expand</title>
    <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none"
      stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"
      class="feather feather-chevron-right">
      <polyline points="9 18 15 12 9 6"></polyline>
    </svg>
  </symbol>
</svg>

<input type="checkbox" class="sidebar-toggle" name="__navigation" id="__navigation">
<input type="checkbox" class="sidebar-toggle" name="__toc" id="__toc">
<label class="overlay sidebar-overlay" for="__navigation"></label>
<label class="overlay toc-overlay" for="__toc"></label>



<div class="page">
  <header class="mobile-header">
    <div class="header-left">
      <label class="nav-overlay-icon" for="__navigation">
        <i class="icon"><svg><use href="#svg-menu"></use></svg></i>
      </label>
    </div>
    <div class="header-center">
      <a href="../index.html"><div class="brand">manim  documentation</div></a>
    </div>
    <div class="header-right">
      <label class="toc-overlay-icon toc-header-icon" for="__toc">
        <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
      </label>
    </div>
  </header>
  <aside class="sidebar-drawer">
    <div class="sidebar-container">
      
      <div class="sidebar-sticky"><a class="sidebar-brand centered" href="../index.html">
  
  <div class="sidebar-logo-container">
    <img class="sidebar-logo" src="../_static/transparent_graph.png" alt="Logo"/>
  </div>
  
  
</a><form class="sidebar-search-container" method="get" action="../search.html">
  <input class="sidebar-search" placeholder=Search name="q">
  <input type="hidden" name="check_keywords" value="yes">
  <input type="hidden" name="area" value="default">
</form><div class="sidebar-scroll"><div class="sidebar-tree">
  <p class="caption"><span class="caption-text">Getting Started</span></p>
<ul class="current">
<li class="toctree-l1"><a class="reference internal" href="installation.html">Installation</a></li>
<li class="toctree-l1"><a class="reference internal" href="quickstart.html">Quick Start</a></li>
<li class="toctree-l1"><a class="reference internal" href="configuration.html">CLI flags and configuration</a></li>
<li class="toctree-l1 current current-page"><a class="current reference internal" href="#">Example Scenes</a></li>
<li class="toctree-l1"><a class="reference internal" href="config.html">CONFIG dictionary</a></li>
<li class="toctree-l1"><a class="reference internal" href="structure.html">Manim’s structure</a></li>
<li class="toctree-l1"><a class="reference internal" href="whatsnew.html">What’s new</a></li>
</ul>
<p class="caption"><span class="caption-text">Documentation</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../documentation/constants.html">constants</a></li>
<li class="toctree-l1"><a class="reference internal" href="../documentation/custom_config.html">custom_config</a></li>
</ul>
<p class="caption"><span class="caption-text">Development</span></p>
<ul>
<li class="toctree-l1"><a class="reference internal" href="../development/changelog.html">Changelog</a></li>
<li class="toctree-l1"><a class="reference internal" href="../development/contributing.html">Contributing</a></li>
<li class="toctree-l1"><a class="reference internal" href="../development/about.html">About</a></li>
</ul>

</div>
</div>
      </div>
      
    </div>
  </aside>
  <main class="main">
    <div class="content">
      <article role="main">
        <label class="toc-overlay-icon toc-content-icon" for="__toc">
          <i class="icon"><svg><use href="#svg-toc"></use></svg></i>
        </label>
        <div class="section" id="example-scenes">
<h1>Example Scenes<a class="headerlink" href="#example-scenes" title="Permalink to this headline">¶</a></h1>
<p>After understanding the previous knowledge, we can understand more scenes.
Many example scenes are given in <code class="docutils literal notranslate"><span class="pre">example_scenes.py</span></code>, let’s start with
the simplest and one by one.</p>
<div class="section" id="interactivedevlopment">
<h2>InteractiveDevlopment<a class="headerlink" href="#interactivedevlopment" title="Permalink to this headline">¶</a></h2>
<div class="manim-example"><video autoplay="" class="manim-video" controls="" id="interactivedevlopment" loop="" src="../_static/example_scenes/InteractiveDevlopment.mp4"></video><h5 class="example-header">InteractiveDevlopment<a class="headerlink" href="#interactivedevlopment">¶</a></h5><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="kn">from</span> <span class="nn">manimlib</span> <span class="kn">import</span> <span class="o">*</span>

<span class="k">class</span> <span class="nc">InteractiveDevlopment</span><span class="p">(</span><span class="n">Scene</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">construct</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">circle</span> <span class="o">=</span> <span class="n">Circle</span><span class="p">()</span>
        <span class="n">circle</span><span class="o">.</span><span class="n">set_fill</span><span class="p">(</span><span class="n">BLUE</span><span class="p">,</span> <span class="n">opacity</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>
        <span class="n">circle</span><span class="o">.</span><span class="n">set_stroke</span><span class="p">(</span><span class="n">BLUE_E</span><span class="p">,</span> <span class="n">width</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
        <span class="n">square</span> <span class="o">=</span> <span class="n">Square</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">ShowCreation</span><span class="p">(</span><span class="n">square</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="c1"># This opens an iPython termnial where you can keep writing</span>
        <span class="c1"># lines as if they were part of this construct method.</span>
        <span class="c1"># In particular, 'square', 'circle' and 'self' will all be</span>
        <span class="c1"># part of the local namespace in that terminal.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">embed</span><span class="p">()</span>

        <span class="c1"># Try copying and pasting some of the lines below into</span>
        <span class="c1"># the interactive shell</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">ReplacementTransform</span><span class="p">(</span><span class="n">square</span><span class="p">,</span> <span class="n">circle</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">circle</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">stretch</span><span class="p">(</span><span class="mi">4</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">Rotate</span><span class="p">(</span><span class="n">circle</span><span class="p">,</span> <span class="mi">90</span> <span class="o">*</span> <span class="n">DEGREES</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">circle</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">shift</span><span class="p">(</span><span class="mi">2</span> <span class="o">*</span> <span class="n">RIGHT</span><span class="p">)</span><span class="o">.</span><span class="n">scale</span><span class="p">(</span><span class="mf">0.25</span><span class="p">))</span>

        <span class="n">text</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span><span class="s2">"""</span>
<span class="s2">            In general, using the interactive shell</span>
<span class="s2">            is very helpful when developing new scenes</span>
<span class="s2">        """</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">Write</span><span class="p">(</span><span class="n">text</span><span class="p">))</span>

        <span class="c1"># In the interactive shell, you can just type</span>
        <span class="c1"># play, add, remove, clear, wait, save_state and restore,</span>
        <span class="c1"># instead of self.play, self.add, self.remove, etc.</span>

        <span class="c1"># To interact with the window, type touch().  You can then</span>
        <span class="c1"># scroll in the window, or zoom by holding down 'z' while scrolling,</span>
        <span class="c1"># and change camera perspective by holding down 'd' while moving</span>
        <span class="c1"># the mouse.  Press 'r' to reset to the standard camera position.</span>
        <span class="c1"># Press 'q' to stop interacting with the window and go back to</span>
        <span class="c1"># typing new commands into the shell.</span>

        <span class="c1"># In principle you can customize a scene to be responsive to</span>
        <span class="c1"># mouse and keyboard interactions</span>
        <span class="n">always</span><span class="p">(</span><span class="n">circle</span><span class="o">.</span><span class="n">move_to</span><span class="p">,</span> <span class="bp">self</span><span class="o">.</span><span class="n">mouse_point</span><span class="p">)</span>
</pre></div>
</div>
</div><p>This scene is similar to what we wrote in <a class="reference internal" href="quickstart.html"><span class="doc">Quick Start</span></a>.
And how to interact has been written in the comments.
No more explanation here.</p>
</div>
<div class="section" id="animatingmethods">
<h2>AnimatingMethods<a class="headerlink" href="#animatingmethods" title="Permalink to this headline">¶</a></h2>
<div class="manim-example"><video autoplay="" class="manim-video" controls="" id="animatingmethods" loop="" src="../_static/example_scenes/AnimatingMethods.mp4"></video><h5 class="example-header">AnimatingMethods<a class="headerlink" href="#animatingmethods">¶</a></h5><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">AnimatingMethods</span><span class="p">(</span><span class="n">Scene</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">construct</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">grid</span> <span class="o">=</span> <span class="n">Tex</span><span class="p">(</span><span class="sa">r</span><span class="s2">"\pi"</span><span class="p">)</span><span class="o">.</span><span class="n">get_grid</span><span class="p">(</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">grid</span><span class="p">)</span>

        <span class="c1"># You can animate the application of mobject methods with the</span>
        <span class="c1"># ".animate" syntax:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">grid</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">shift</span><span class="p">(</span><span class="n">LEFT</span><span class="p">))</span>

        <span class="c1"># Alternatively, you can use the older syntax by passing the</span>
        <span class="c1"># method and then the arguments to the scene's "play" function:</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">grid</span><span class="o">.</span><span class="n">shift</span><span class="p">,</span> <span class="n">LEFT</span><span class="p">)</span>

        <span class="c1"># Both of those will interpolate between the mobject's initial</span>
        <span class="c1"># state and whatever happens when you apply that method.</span>
        <span class="c1"># For this example, calling grid.shift(LEFT) would shift the</span>
        <span class="c1"># grid one unit to the left, but both of the previous calls to</span>
        <span class="c1"># "self.play" animate that motion.</span>

        <span class="c1"># The same applies for any method, including those setting colors.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">grid</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">set_color</span><span class="p">(</span><span class="n">YELLOW</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">grid</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">set_submobject_colors_by_gradient</span><span class="p">(</span><span class="n">BLUE</span><span class="p">,</span> <span class="n">GREEN</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">grid</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">set_height</span><span class="p">(</span><span class="n">TAU</span> <span class="o">-</span> <span class="n">MED_SMALL_BUFF</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="c1"># The method Mobject.apply_complex_function lets you apply arbitrary</span>
        <span class="c1"># complex functions, treating the points defining the mobject as</span>
        <span class="c1"># complex numbers.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">grid</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">apply_complex_function</span><span class="p">(</span><span class="n">np</span><span class="o">.</span><span class="n">exp</span><span class="p">),</span> <span class="n">run_time</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="c1"># Even more generally, you could apply Mobject.apply_function,</span>
        <span class="c1"># which takes in functions form R^3 to R^3</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">grid</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">apply_function</span><span class="p">(</span>
                <span class="k">lambda</span> <span class="n">p</span><span class="p">:</span> <span class="p">[</span>
                    <span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span> <span class="o">+</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
                    <span class="n">p</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span> <span class="o">+</span> <span class="mf">0.5</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">p</span><span class="p">[</span><span class="mi">0</span><span class="p">]),</span>
                    <span class="n">p</span><span class="p">[</span><span class="mi">2</span><span class="p">]</span>
                <span class="p">]</span>
            <span class="p">),</span>
            <span class="n">run_time</span><span class="o">=</span><span class="mi">5</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
</pre></div>
</div>
</div><p>The new usage in this scene is <code class="docutils literal notranslate"><span class="pre">.get_grid()</span></code> and <code class="docutils literal notranslate"><span class="pre">self.play(mob.animate.method(args))</span></code>.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">.get_grid()</span></code> method will return a new mobject containing multiple copies of this one arranged in a grid.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">self.play(mob.animate.method(args))</span></code> animates the method, and the details are in the comments above.</p></li>
</ul>
</div>
<div class="section" id="textexample">
<h2>TextExample<a class="headerlink" href="#textexample" title="Permalink to this headline">¶</a></h2>
<div class="manim-example"><video autoplay="" class="manim-video" controls="" id="textexample" loop="" src="../_static/example_scenes/TextExample.mp4"></video><h5 class="example-header">TextExample<a class="headerlink" href="#textexample">¶</a></h5><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">TextExample</span><span class="p">(</span><span class="n">Scene</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">construct</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">text</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span><span class="s2">"Here is a text"</span><span class="p">,</span> <span class="n">font</span><span class="o">=</span><span class="s2">"Consolas"</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">90</span><span class="p">)</span>
        <span class="n">difference</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span>
            <span class="sd">"""</span>
<span class="sd">            The most important difference between Text and TexText is that\n</span>
<span class="sd">            you can change the font more easily, but can't use the LaTeX grammar</span>
<span class="sd">            """</span><span class="p">,</span>
            <span class="n">font</span><span class="o">=</span><span class="s2">"Arial"</span><span class="p">,</span> <span class="n">font_size</span><span class="o">=</span><span class="mi">24</span><span class="p">,</span>
            <span class="n">t2c</span><span class="o">=</span><span class="p">{</span><span class="s2">"Text"</span><span class="p">:</span> <span class="n">BLUE</span><span class="p">,</span> <span class="s2">"TexText"</span><span class="p">:</span> <span class="n">BLUE</span><span class="p">,</span> <span class="s2">"LaTeX"</span><span class="p">:</span> <span class="n">ORANGE</span><span class="p">}</span>
        <span class="p">)</span>
        <span class="n">VGroup</span><span class="p">(</span><span class="n">text</span><span class="p">,</span> <span class="n">difference</span><span class="p">)</span><span class="o">.</span><span class="n">arrange</span><span class="p">(</span><span class="n">DOWN</span><span class="p">,</span> <span class="n">buff</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">Write</span><span class="p">(</span><span class="n">text</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">FadeIn</span><span class="p">(</span><span class="n">difference</span><span class="p">,</span> <span class="n">UP</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>

        <span class="n">fonts</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span>
            <span class="s2">"And you can also set the font according to different words"</span><span class="p">,</span>
            <span class="n">font</span><span class="o">=</span><span class="s2">"Arial"</span><span class="p">,</span>
            <span class="n">t2f</span><span class="o">=</span><span class="p">{</span><span class="s2">"font"</span><span class="p">:</span> <span class="s2">"Consolas"</span><span class="p">,</span> <span class="s2">"words"</span><span class="p">:</span> <span class="s2">"Consolas"</span><span class="p">},</span>
            <span class="n">t2c</span><span class="o">=</span><span class="p">{</span><span class="s2">"font"</span><span class="p">:</span> <span class="n">BLUE</span><span class="p">,</span> <span class="s2">"words"</span><span class="p">:</span> <span class="n">GREEN</span><span class="p">}</span>
        <span class="p">)</span>
        <span class="n">slant</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span>
            <span class="s2">"And the same as slant and weight"</span><span class="p">,</span>
            <span class="n">font</span><span class="o">=</span><span class="s2">"Consolas"</span><span class="p">,</span>
            <span class="n">t2s</span><span class="o">=</span><span class="p">{</span><span class="s2">"slant"</span><span class="p">:</span> <span class="n">ITALIC</span><span class="p">},</span>
            <span class="n">t2w</span><span class="o">=</span><span class="p">{</span><span class="s2">"weight"</span><span class="p">:</span> <span class="n">BOLD</span><span class="p">},</span>
            <span class="n">t2c</span><span class="o">=</span><span class="p">{</span><span class="s2">"slant"</span><span class="p">:</span> <span class="n">ORANGE</span><span class="p">,</span> <span class="s2">"weight"</span><span class="p">:</span> <span class="n">RED</span><span class="p">}</span>
        <span class="p">)</span>
        <span class="n">VGroup</span><span class="p">(</span><span class="n">fonts</span><span class="p">,</span> <span class="n">slant</span><span class="p">)</span><span class="o">.</span><span class="n">arrange</span><span class="p">(</span><span class="n">DOWN</span><span class="p">,</span> <span class="n">buff</span><span class="o">=</span><span class="mf">0.8</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">FadeOut</span><span class="p">(</span><span class="n">text</span><span class="p">),</span> <span class="n">FadeOut</span><span class="p">(</span><span class="n">difference</span><span class="p">,</span> <span class="n">shift</span><span class="o">=</span><span class="n">DOWN</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">Write</span><span class="p">(</span><span class="n">fonts</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">Write</span><span class="p">(</span><span class="n">slant</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
</pre></div>
</div>
</div><p>The new classes in this scene are <code class="docutils literal notranslate"><span class="pre">Text</span></code>, <code class="docutils literal notranslate"><span class="pre">VGroup</span></code>, <code class="docutils literal notranslate"><span class="pre">Write</span></code>, <code class="docutils literal notranslate"><span class="pre">FadeIn</span></code> and <code class="docutils literal notranslate"><span class="pre">FadeOut</span></code>.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">Text</span></code> can create text, define fonts, etc. The usage ais clearly reflected in the above examples.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">VGroup</span></code> can put multiple <code class="docutils literal notranslate"><span class="pre">VMobject</span></code> together as a whole. In the example, the <code class="docutils literal notranslate"><span class="pre">.arrange()</span></code> method is called to arrange the sub-mobjects in sequence downward (<code class="docutils literal notranslate"><span class="pre">DOWN</span></code>), and the spacing is <code class="docutils literal notranslate"><span class="pre">buff</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">Write</span></code> is an animation that shows similar writing effects.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">FadeIn</span></code> fades the object in, the second parameter indicates the direction of the fade in.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">FadeOut</span></code> fades out the object, the second parameter indicates the direction of the fade out.</p></li>
</ul>
</div>
<div class="section" id="textransformexample">
<h2>TexTransformExample<a class="headerlink" href="#textransformexample" title="Permalink to this headline">¶</a></h2>
<div class="manim-example"><video autoplay="" class="manim-video" controls="" id="textransformexample" loop="" src="../_static/example_scenes/TexTransformExample.mp4"></video><h5 class="example-header">TexTransformExample<a class="headerlink" href="#textransformexample">¶</a></h5><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">TexTransformExample</span><span class="p">(</span><span class="n">Scene</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">construct</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">to_isolate</span> <span class="o">=</span> <span class="p">[</span><span class="s2">"B"</span><span class="p">,</span> <span class="s2">"C"</span><span class="p">,</span> <span class="s2">"="</span><span class="p">,</span> <span class="s2">"("</span><span class="p">,</span> <span class="s2">")"</span><span class="p">]</span>
        <span class="n">lines</span> <span class="o">=</span> <span class="n">VGroup</span><span class="p">(</span>
            <span class="c1"># Surrounding substrings with double braces</span>
            <span class="c1"># will ensure that those parts are separated</span>
            <span class="c1"># out in the Tex.  For example, here the</span>
            <span class="c1"># Tex will have 5 submobjects, corresponding</span>
            <span class="c1"># to the strings [A^2, +, B^2, =, C^2]</span>
            <span class="n">Tex</span><span class="p">(</span><span class="s2">"{{A^2}} + {{B^2}} = {{C^2}}"</span><span class="p">),</span>
            <span class="n">Tex</span><span class="p">(</span><span class="s2">"{{A^2}} = {{C^2}} - {{B^2}}"</span><span class="p">),</span>
            <span class="c1"># Alternatively, you can pass in the keyword argument</span>
            <span class="c1"># "isolate" with a list of strings that should be out as</span>
            <span class="c1"># their own submobject.  So both lines below are equivalent</span>
            <span class="c1"># to what you'd get by wrapping every instance of "B", "C"</span>
            <span class="c1"># "=", "(" and ")" with double braces</span>
            <span class="n">Tex</span><span class="p">(</span><span class="s2">"{{A^2}} = (C + B)(C - B)"</span><span class="p">,</span> <span class="n">isolate</span><span class="o">=</span><span class="n">to_isolate</span><span class="p">),</span>
            <span class="n">Tex</span><span class="p">(</span><span class="s2">"A = </span><span class="se">\\</span><span class="s2">sqrt{(C + B)(C - B)}"</span><span class="p">,</span> <span class="n">isolate</span><span class="o">=</span><span class="n">to_isolate</span><span class="p">)</span>
        <span class="p">)</span>
        <span class="n">lines</span><span class="o">.</span><span class="n">arrange</span><span class="p">(</span><span class="n">DOWN</span><span class="p">,</span> <span class="n">buff</span><span class="o">=</span><span class="n">LARGE_BUFF</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">line</span> <span class="ow">in</span> <span class="n">lines</span><span class="p">:</span>
            <span class="n">line</span><span class="o">.</span><span class="n">set_color_by_tex_to_color_map</span><span class="p">({</span>
                <span class="s2">"A"</span><span class="p">:</span> <span class="n">BLUE</span><span class="p">,</span>
                <span class="s2">"B"</span><span class="p">:</span> <span class="n">TEAL</span><span class="p">,</span>
                <span class="s2">"C"</span><span class="p">:</span> <span class="n">GREEN</span><span class="p">,</span>
            <span class="p">})</span>

        <span class="n">play_kw</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"run_time"</span><span class="p">:</span> <span class="mi">2</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">])</span>
        <span class="c1"># The animation TransformMatchingTex will line up parts</span>
        <span class="c1"># of the source and target which have matching tex strings.</span>
        <span class="c1"># Here, giving it a little path_arc makes each part sort of</span>
        <span class="c1"># rotate into their final positions, which feels appropriate</span>
        <span class="c1"># for the idea of rearranging an equation</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">TransformMatchingTex</span><span class="p">(</span>
                <span class="n">lines</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span> <span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">],</span>
                <span class="n">path_arc</span><span class="o">=</span><span class="mi">90</span> <span class="o">*</span> <span class="n">DEGREES</span><span class="p">,</span>
            <span class="p">),</span>
            <span class="o">**</span><span class="n">play_kw</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="c1"># Now, we could try this again on the next line...</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">TransformMatchingTex</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span> <span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
            <span class="o">**</span><span class="n">play_kw</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="c1"># ...and this looks nice enough, but since there's no tex</span>
        <span class="c1"># in lines[2] which matches "C^2" or "B^2", those terms fade</span>
        <span class="c1"># out to nothing while the C and B terms fade in from nothing.</span>
        <span class="c1"># If, however, we want the C^2 to go to C, and B^2 to go to B,</span>
        <span class="c1"># we can specify that with a key map.</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">FadeOut</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">]))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">TransformMatchingTex</span><span class="p">(</span>
                <span class="n">lines</span><span class="p">[</span><span class="mi">1</span><span class="p">]</span><span class="o">.</span><span class="n">copy</span><span class="p">(),</span> <span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">],</span>
                <span class="n">key_map</span><span class="o">=</span><span class="p">{</span>
                    <span class="s2">"C^2"</span><span class="p">:</span> <span class="s2">"C"</span><span class="p">,</span>
                    <span class="s2">"B^2"</span><span class="p">:</span> <span class="s2">"B"</span><span class="p">,</span>
                <span class="p">}</span>
            <span class="p">),</span>
            <span class="o">**</span><span class="n">play_kw</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="c1"># And to finish off, a simple TransformMatchingShapes would work</span>
        <span class="c1"># just fine.  But perhaps we want that exponent on A^2 to transform into</span>
        <span class="c1"># the square root symbol.  At the moment, lines[2] treats the expression</span>
        <span class="c1"># A^2 as a unit, so we might create a new version of the same line which</span>
        <span class="c1"># separates out just the A.  This way, when TransformMatchingTex lines up</span>
        <span class="c1"># all matching parts, the only mismatch will be between the "^2" from</span>
        <span class="c1"># new_line2 and the "\sqrt" from the final line.  By passing in,</span>
        <span class="c1"># transform_mismatches=True, it will transform this "^2" part into</span>
        <span class="c1"># the "\sqrt" part.</span>
        <span class="n">new_line2</span> <span class="o">=</span> <span class="n">Tex</span><span class="p">(</span><span class="s2">"{{A}}^2 = (C + B)(C - B)"</span><span class="p">,</span> <span class="n">isolate</span><span class="o">=</span><span class="n">to_isolate</span><span class="p">)</span>
        <span class="n">new_line2</span><span class="o">.</span><span class="n">replace</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>
        <span class="n">new_line2</span><span class="o">.</span><span class="n">match_style</span><span class="p">(</span><span class="n">lines</span><span class="p">[</span><span class="mi">2</span><span class="p">])</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">TransformMatchingTex</span><span class="p">(</span>
                <span class="n">new_line2</span><span class="p">,</span> <span class="n">lines</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span>
                <span class="n">transform_mismatches</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
            <span class="p">),</span>
            <span class="o">**</span><span class="n">play_kw</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">FadeOut</span><span class="p">(</span><span class="n">lines</span><span class="p">,</span> <span class="n">RIGHT</span><span class="p">))</span>

        <span class="c1"># Alternatively, if you don't want to think about breaking up</span>
        <span class="c1"># the tex strings deliberately, you can TransformMatchingShapes,</span>
        <span class="c1"># which will try to line up all pieces of a source mobject with</span>
        <span class="c1"># those of a target, regardless of the submobject hierarchy in</span>
        <span class="c1"># each one, according to whether those pieces have the same</span>
        <span class="c1"># shape (as best it can).</span>
        <span class="n">source</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span><span class="s2">"the morse code"</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">target</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span><span class="s2">"here come dots"</span><span class="p">,</span> <span class="n">height</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">Write</span><span class="p">(</span><span class="n">source</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="n">kw</span> <span class="o">=</span> <span class="p">{</span><span class="s2">"run_time"</span><span class="p">:</span> <span class="mi">3</span><span class="p">,</span> <span class="s2">"path_arc"</span><span class="p">:</span> <span class="n">PI</span> <span class="o">/</span> <span class="mi">2</span><span class="p">}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">TransformMatchingShapes</span><span class="p">(</span><span class="n">source</span><span class="p">,</span> <span class="n">target</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">TransformMatchingShapes</span><span class="p">(</span><span class="n">target</span><span class="p">,</span> <span class="n">source</span><span class="p">,</span> <span class="o">**</span><span class="n">kw</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
</pre></div>
</div>
</div><p>The new classes in this scene are <code class="docutils literal notranslate"><span class="pre">Tex</span></code>, <code class="docutils literal notranslate"><span class="pre">TexText</span></code>, <code class="docutils literal notranslate"><span class="pre">TransformMatchingTex</span></code>
and <code class="docutils literal notranslate"><span class="pre">TransformMatchingShapes</span></code>.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">Tex</span></code> uses LaTeX to create mathematical formulas.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">TexText</span></code> uses LaTeX to create text.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">TransformMatchingTeX</span></code> automatically transforms sub-objects according to the similarities and differences of tex in <code class="docutils literal notranslate"><span class="pre">Tex</span></code>.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">TransformMatchingShapes</span></code> automatically transform sub-objects directly based on the similarities and differences of the object point sets.</p></li>
</ul>
</div>
<div class="section" id="updatersexample">
<h2>UpdatersExample<a class="headerlink" href="#updatersexample" title="Permalink to this headline">¶</a></h2>
<div class="manim-example"><video autoplay="" class="manim-video" controls="" id="updatersexample" loop="" src="../_static/example_scenes/UpdatersExample.mp4"></video><h5 class="example-header">UpdatersExample<a class="headerlink" href="#updatersexample">¶</a></h5><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">UpdatersExample</span><span class="p">(</span><span class="n">Scene</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">construct</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">square</span> <span class="o">=</span> <span class="n">Square</span><span class="p">()</span>
        <span class="n">square</span><span class="o">.</span><span class="n">set_fill</span><span class="p">(</span><span class="n">BLUE_E</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>

        <span class="c1"># On all all frames, the constructor Brace(square, UP) will</span>
        <span class="c1"># be called, and the mobject brace will set its data to match</span>
        <span class="c1"># that of the newly constructed object</span>
        <span class="n">brace</span> <span class="o">=</span> <span class="n">always_redraw</span><span class="p">(</span><span class="n">Brace</span><span class="p">,</span> <span class="n">square</span><span class="p">,</span> <span class="n">UP</span><span class="p">)</span>

        <span class="n">text</span><span class="p">,</span> <span class="n">number</span> <span class="o">=</span> <span class="n">label</span> <span class="o">=</span> <span class="n">VGroup</span><span class="p">(</span>
            <span class="n">Text</span><span class="p">(</span><span class="s2">"Width = "</span><span class="p">),</span>
            <span class="n">DecimalNumber</span><span class="p">(</span>
                <span class="mi">0</span><span class="p">,</span>
                <span class="n">show_ellipsis</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
                <span class="n">num_decimal_places</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
                <span class="n">include_sign</span><span class="o">=</span><span class="kc">True</span><span class="p">,</span>
            <span class="p">)</span>
        <span class="p">)</span>
        <span class="n">label</span><span class="o">.</span><span class="n">arrange</span><span class="p">(</span><span class="n">RIGHT</span><span class="p">)</span>

        <span class="c1"># This ensures that the method deicmal.next_to(square)</span>
        <span class="c1"># is called on every frame</span>
        <span class="n">always</span><span class="p">(</span><span class="n">label</span><span class="o">.</span><span class="n">next_to</span><span class="p">,</span> <span class="n">brace</span><span class="p">,</span> <span class="n">UP</span><span class="p">)</span>
        <span class="c1"># You could also write the following equivalent line</span>
        <span class="c1"># label.add_updater(lambda m: m.next_to(brace, UP))</span>

        <span class="c1"># If the argument itself might change, you can use f_always,</span>
        <span class="c1"># for which the arguments following the initial Mobject method</span>
        <span class="c1"># should be functions returning arguments to that method.</span>
        <span class="c1"># The following line ensures thst decimal.set_value(square.get_y())</span>
        <span class="c1"># is called every frame</span>
        <span class="n">f_always</span><span class="p">(</span><span class="n">number</span><span class="o">.</span><span class="n">set_value</span><span class="p">,</span> <span class="n">square</span><span class="o">.</span><span class="n">get_width</span><span class="p">)</span>
        <span class="c1"># You could also write the following equivalent line</span>
        <span class="c1"># number.add_updater(lambda m: m.set_value(square.get_width()))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">square</span><span class="p">,</span> <span class="n">brace</span><span class="p">,</span> <span class="n">label</span><span class="p">)</span>

        <span class="c1"># Notice that the brace and label track with the square</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">square</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">scale</span><span class="p">(</span><span class="mi">2</span><span class="p">),</span>
            <span class="n">rate_func</span><span class="o">=</span><span class="n">there_and_back</span><span class="p">,</span>
            <span class="n">run_time</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">square</span><span class="o">.</span><span class="n">set_width</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="n">stretch</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span>
            <span class="n">run_time</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">square</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">set_width</span><span class="p">(</span><span class="mi">2</span><span class="p">),</span>
            <span class="n">run_time</span><span class="o">=</span><span class="mi">3</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="c1"># In general, you can alway call Mobject.add_updater, and pass in</span>
        <span class="c1"># a function that you want to be called on every frame.  The function</span>
        <span class="c1"># should take in either one argument, the mobject, or two arguments,</span>
        <span class="c1"># the mobject and the amount of time since the last frame.</span>
        <span class="n">now</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">time</span>
        <span class="n">w0</span> <span class="o">=</span> <span class="n">square</span><span class="o">.</span><span class="n">get_width</span><span class="p">()</span>
        <span class="n">square</span><span class="o">.</span><span class="n">add_updater</span><span class="p">(</span>
            <span class="k">lambda</span> <span class="n">m</span><span class="p">:</span> <span class="n">m</span><span class="o">.</span><span class="n">set_width</span><span class="p">(</span><span class="n">w0</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">cos</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">time</span> <span class="o">-</span> <span class="n">now</span><span class="p">))</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">(</span><span class="mi">4</span> <span class="o">*</span> <span class="n">PI</span><span class="p">)</span>
</pre></div>
</div>
</div><p>The new classes and usage in this scene are <code class="docutils literal notranslate"><span class="pre">always_redraw()</span></code>, <code class="docutils literal notranslate"><span class="pre">DecimalNumber</span></code>, <code class="docutils literal notranslate"><span class="pre">.to_edge()</span></code>,
<code class="docutils literal notranslate"><span class="pre">.center()</span></code>, <code class="docutils literal notranslate"><span class="pre">always()</span></code>, <code class="docutils literal notranslate"><span class="pre">f_always()</span></code>, <code class="docutils literal notranslate"><span class="pre">.set_y()</span></code> and <code class="docutils literal notranslate"><span class="pre">.add_updater()</span></code>.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">always_redraw()</span></code> function create a new mobject every frame.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">DecimalNumber</span></code> is a variable number, speed it up by breaking it into <code class="docutils literal notranslate"><span class="pre">Text</span></code> characters.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">.to_edge()</span></code> means to place the object on the edge of the screen.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">.center()</span></code> means to place the object in the center of the screen.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">always(f,</span> <span class="pre">x)</span></code> means that a certain function (<code class="docutils literal notranslate"><span class="pre">f(x)</span></code>) is executed every frame.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">f_always(f,</span> <span class="pre">g)</span></code> is similar to <code class="docutils literal notranslate"><span class="pre">always</span></code>, executed <code class="docutils literal notranslate"><span class="pre">f(g())</span></code> every frame.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">.set_y()</span></code> means to set the ordinate of the object on the screen.</p></li>
<li><p><code class="docutils literal notranslate"><span class="pre">.add_updater()</span></code> sets an update function for the object. For example: <code class="docutils literal notranslate"><span class="pre">mob1.add_updater(lambda</span> <span class="pre">mob:</span> <span class="pre">mob.next_to(mob2))</span></code> means <code class="docutils literal notranslate"><span class="pre">mob1.next_to(mob2)</span></code> is executed every frame.</p></li>
</ul>
</div>
<div class="section" id="coordinatesystemexample">
<h2>CoordinateSystemExample<a class="headerlink" href="#coordinatesystemexample" title="Permalink to this headline">¶</a></h2>
<div class="manim-example"><video autoplay="" class="manim-video" controls="" id="coordinatesystemexample" loop="" src="../_static/example_scenes/CoordinateSystemExample.mp4"></video><h5 class="example-header">CoordinateSystemExample<a class="headerlink" href="#coordinatesystemexample">¶</a></h5><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">CoordinateSystemExample</span><span class="p">(</span><span class="n">Scene</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">construct</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">axes</span> <span class="o">=</span> <span class="n">Axes</span><span class="p">(</span>
            <span class="c1"># x-axis ranges from -1 to 10, with a default step size of 1</span>
            <span class="n">x_range</span><span class="o">=</span><span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span>
            <span class="c1"># y-axis ranges from -2 to 10 with a step size of 0.5</span>
            <span class="n">y_range</span><span class="o">=</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">,</span> <span class="mi">2</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">),</span>
            <span class="c1"># The axes will be stretched so as to match the specified</span>
            <span class="c1"># height and width</span>
            <span class="n">height</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span>
            <span class="n">width</span><span class="o">=</span><span class="mi">10</span><span class="p">,</span>
            <span class="c1"># Axes is made of two NumberLine mobjects.  You can specify</span>
            <span class="c1"># their configuration with axis_config</span>
            <span class="n">axis_config</span><span class="o">=</span><span class="p">{</span>
                <span class="s2">"stroke_color"</span><span class="p">:</span> <span class="n">GREY_A</span><span class="p">,</span>
                <span class="s2">"stroke_width"</span><span class="p">:</span> <span class="mi">2</span><span class="p">,</span>
            <span class="p">},</span>
            <span class="c1"># Alternatively, you can specify configuration for just one</span>
            <span class="c1"># of them, like this.</span>
            <span class="n">y_axis_config</span><span class="o">=</span><span class="p">{</span>
                <span class="s2">"include_tip"</span><span class="p">:</span> <span class="kc">False</span><span class="p">,</span>
            <span class="p">}</span>
        <span class="p">)</span>
        <span class="c1"># Keyword arguments of add_coordinate_labels can be used to</span>
        <span class="c1"># configure the DecimalNumber mobjects which it creates and</span>
        <span class="c1"># adds to the axes</span>
        <span class="n">axes</span><span class="o">.</span><span class="n">add_coordinate_labels</span><span class="p">(</span>
            <span class="n">font_size</span><span class="o">=</span><span class="mi">20</span><span class="p">,</span>
            <span class="n">num_decimal_places</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">axes</span><span class="p">)</span>

        <span class="c1"># Axes descends from the CoordinateSystem class, meaning</span>
        <span class="c1"># you can call call axes.coords_to_point, abbreviated to</span>
        <span class="c1"># axes.c2p, to associate a set of coordinates with a point,</span>
        <span class="c1"># like so:</span>
        <span class="n">dot</span> <span class="o">=</span> <span class="n">Dot</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="n">RED</span><span class="p">)</span>
        <span class="n">dot</span><span class="o">.</span><span class="n">move_to</span><span class="p">(</span><span class="n">axes</span><span class="o">.</span><span class="n">c2p</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="mi">0</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">FadeIn</span><span class="p">(</span><span class="n">dot</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mf">0.5</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">move_to</span><span class="p">(</span><span class="n">axes</span><span class="o">.</span><span class="n">c2p</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="mi">2</span><span class="p">)))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">move_to</span><span class="p">(</span><span class="n">axes</span><span class="o">.</span><span class="n">c2p</span><span class="p">(</span><span class="mi">5</span><span class="p">,</span> <span class="mf">0.5</span><span class="p">)))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="c1"># Similarly, you can call axes.point_to_coords, or axes.p2c</span>
        <span class="c1"># print(axes.p2c(dot.get_center()))</span>

        <span class="c1"># We can draw lines from the axes to better mark the coordinates</span>
        <span class="c1"># of a given point.</span>
        <span class="c1"># Here, the always_redraw command means that on each new frame</span>
        <span class="c1"># the lines will be redrawn</span>
        <span class="n">h_line</span> <span class="o">=</span> <span class="n">always_redraw</span><span class="p">(</span><span class="k">lambda</span><span class="p">:</span> <span class="n">axes</span><span class="o">.</span><span class="n">get_h_line</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">get_left</span><span class="p">()))</span>
        <span class="n">v_line</span> <span class="o">=</span> <span class="n">always_redraw</span><span class="p">(</span><span class="k">lambda</span><span class="p">:</span> <span class="n">axes</span><span class="o">.</span><span class="n">get_v_line</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">get_bottom</span><span class="p">()))</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">ShowCreation</span><span class="p">(</span><span class="n">h_line</span><span class="p">),</span>
            <span class="n">ShowCreation</span><span class="p">(</span><span class="n">v_line</span><span class="p">),</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">move_to</span><span class="p">(</span><span class="n">axes</span><span class="o">.</span><span class="n">c2p</span><span class="p">(</span><span class="mi">3</span><span class="p">,</span> <span class="o">-</span><span class="mi">2</span><span class="p">)))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">move_to</span><span class="p">(</span><span class="n">axes</span><span class="o">.</span><span class="n">c2p</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">)))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="c1"># If we tie the dot to a particular set of coordinates, notice</span>
        <span class="c1"># that as we move the axes around it respects the coordinate</span>
        <span class="c1"># system defined by them.</span>
        <span class="n">f_always</span><span class="p">(</span><span class="n">dot</span><span class="o">.</span><span class="n">move_to</span><span class="p">,</span> <span class="k">lambda</span><span class="p">:</span> <span class="n">axes</span><span class="o">.</span><span class="n">c2p</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">axes</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">scale</span><span class="p">(</span><span class="mf">0.75</span><span class="p">),</span>
            <span class="n">axes</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">to_corner</span><span class="p">(</span><span class="n">UL</span><span class="p">),</span>
            <span class="n">run_time</span><span class="o">=</span><span class="mi">2</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">FadeOut</span><span class="p">(</span><span class="n">VGroup</span><span class="p">(</span><span class="n">axes</span><span class="p">,</span> <span class="n">dot</span><span class="p">,</span> <span class="n">h_line</span><span class="p">,</span> <span class="n">v_line</span><span class="p">)))</span>

        <span class="c1"># Other coordinate systems you can play around with include</span>
        <span class="c1"># ThreeDAxes, NumberPlane, and ComplexPlane.</span>
</pre></div>
</div>
</div></div>
<div class="section" id="graphexample">
<h2>GraphExample<a class="headerlink" href="#graphexample" title="Permalink to this headline">¶</a></h2>
<div class="manim-example"><video autoplay="" class="manim-video" controls="" id="graphexample" loop="" src="../_static/example_scenes/GraphExample.mp4"></video><h5 class="example-header">GraphExample<a class="headerlink" href="#graphexample">¶</a></h5><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">GraphExample</span><span class="p">(</span><span class="n">Scene</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">construct</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">axes</span> <span class="o">=</span> <span class="n">Axes</span><span class="p">((</span><span class="o">-</span><span class="mi">3</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="p">(</span><span class="o">-</span><span class="mi">1</span><span class="p">,</span> <span class="mi">8</span><span class="p">))</span>
        <span class="n">axes</span><span class="o">.</span><span class="n">add_coordinate_labels</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">Write</span><span class="p">(</span><span class="n">axes</span><span class="p">,</span> <span class="n">lag_ratio</span><span class="o">=</span><span class="mf">0.01</span><span class="p">,</span> <span class="n">run_time</span><span class="o">=</span><span class="mi">1</span><span class="p">))</span>

        <span class="c1"># Axes.get_graph will return the graph of a function</span>
        <span class="n">sin_graph</span> <span class="o">=</span> <span class="n">axes</span><span class="o">.</span><span class="n">get_graph</span><span class="p">(</span>
            <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mi">2</span> <span class="o">*</span> <span class="n">math</span><span class="o">.</span><span class="n">sin</span><span class="p">(</span><span class="n">x</span><span class="p">),</span>
            <span class="n">color</span><span class="o">=</span><span class="n">BLUE</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="c1"># By default, it draws it so as to somewhat smoothly interpolate</span>
        <span class="c1"># between sampled points (x, f(x)).  If the graph is meant to have</span>
        <span class="c1"># a corner, though, you can set use_smoothing to False</span>
        <span class="n">relu_graph</span> <span class="o">=</span> <span class="n">axes</span><span class="o">.</span><span class="n">get_graph</span><span class="p">(</span>
            <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="nb">max</span><span class="p">(</span><span class="n">x</span><span class="p">,</span> <span class="mi">0</span><span class="p">),</span>
            <span class="n">use_smoothing</span><span class="o">=</span><span class="kc">False</span><span class="p">,</span>
            <span class="n">color</span><span class="o">=</span><span class="n">YELLOW</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="c1"># For discontinuous functions, you can specify the point of</span>
        <span class="c1"># discontinuity so that it does not try to draw over the gap.</span>
        <span class="n">step_graph</span> <span class="o">=</span> <span class="n">axes</span><span class="o">.</span><span class="n">get_graph</span><span class="p">(</span>
            <span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">2.0</span> <span class="k">if</span> <span class="n">x</span> <span class="o">&gt;</span> <span class="mi">3</span> <span class="k">else</span> <span class="mf">1.0</span><span class="p">,</span>
            <span class="n">discontinuities</span><span class="o">=</span><span class="p">[</span><span class="mi">3</span><span class="p">],</span>
            <span class="n">color</span><span class="o">=</span><span class="n">GREEN</span><span class="p">,</span>
        <span class="p">)</span>

        <span class="c1"># Axes.get_graph_label takes in either a string or a mobject.</span>
        <span class="c1"># If it's a string, it treats it as a LaTeX expression.  By default</span>
        <span class="c1"># it places the label next to the graph near the right side, and</span>
        <span class="c1"># has it match the color of the graph</span>
        <span class="n">sin_label</span> <span class="o">=</span> <span class="n">axes</span><span class="o">.</span><span class="n">get_graph_label</span><span class="p">(</span><span class="n">sin_graph</span><span class="p">,</span> <span class="s2">"</span><span class="se">\\</span><span class="s2">sin(x)"</span><span class="p">)</span>
        <span class="n">relu_label</span> <span class="o">=</span> <span class="n">axes</span><span class="o">.</span><span class="n">get_graph_label</span><span class="p">(</span><span class="n">relu_graph</span><span class="p">,</span> <span class="n">Text</span><span class="p">(</span><span class="s2">"ReLU"</span><span class="p">))</span>
        <span class="n">step_label</span> <span class="o">=</span> <span class="n">axes</span><span class="o">.</span><span class="n">get_graph_label</span><span class="p">(</span><span class="n">step_graph</span><span class="p">,</span> <span class="n">Text</span><span class="p">(</span><span class="s2">"Step"</span><span class="p">),</span> <span class="n">x</span><span class="o">=</span><span class="mi">4</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">ShowCreation</span><span class="p">(</span><span class="n">sin_graph</span><span class="p">),</span>
            <span class="n">FadeIn</span><span class="p">(</span><span class="n">sin_label</span><span class="p">,</span> <span class="n">RIGHT</span><span class="p">),</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">ReplacementTransform</span><span class="p">(</span><span class="n">sin_graph</span><span class="p">,</span> <span class="n">relu_graph</span><span class="p">),</span>
            <span class="n">FadeTransform</span><span class="p">(</span><span class="n">sin_label</span><span class="p">,</span> <span class="n">relu_label</span><span class="p">),</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">ReplacementTransform</span><span class="p">(</span><span class="n">relu_graph</span><span class="p">,</span> <span class="n">step_graph</span><span class="p">),</span>
            <span class="n">FadeTransform</span><span class="p">(</span><span class="n">relu_label</span><span class="p">,</span> <span class="n">step_label</span><span class="p">),</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="n">parabola</span> <span class="o">=</span> <span class="n">axes</span><span class="o">.</span><span class="n">get_graph</span><span class="p">(</span><span class="k">lambda</span> <span class="n">x</span><span class="p">:</span> <span class="mf">0.25</span> <span class="o">*</span> <span class="n">x</span><span class="o">**</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">parabola</span><span class="o">.</span><span class="n">set_stroke</span><span class="p">(</span><span class="n">BLUE</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">FadeOut</span><span class="p">(</span><span class="n">step_graph</span><span class="p">),</span>
            <span class="n">FadeOut</span><span class="p">(</span><span class="n">step_label</span><span class="p">),</span>
            <span class="n">ShowCreation</span><span class="p">(</span><span class="n">parabola</span><span class="p">)</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="c1"># You can use axes.input_to_graph_point, abbreviated</span>
        <span class="c1"># to axes.i2gp, to find a particular point on a graph</span>
        <span class="n">dot</span> <span class="o">=</span> <span class="n">Dot</span><span class="p">(</span><span class="n">color</span><span class="o">=</span><span class="n">RED</span><span class="p">)</span>
        <span class="n">dot</span><span class="o">.</span><span class="n">move_to</span><span class="p">(</span><span class="n">axes</span><span class="o">.</span><span class="n">i2gp</span><span class="p">(</span><span class="mi">2</span><span class="p">,</span> <span class="n">parabola</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">FadeIn</span><span class="p">(</span><span class="n">dot</span><span class="p">,</span> <span class="n">scale</span><span class="o">=</span><span class="mf">0.5</span><span class="p">))</span>

        <span class="c1"># A value tracker lets us animate a parameter, usually</span>
        <span class="c1"># with the intent of having other mobjects update based</span>
        <span class="c1"># on the parameter</span>
        <span class="n">x_tracker</span> <span class="o">=</span> <span class="n">ValueTracker</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
        <span class="n">f_always</span><span class="p">(</span>
            <span class="n">dot</span><span class="o">.</span><span class="n">move_to</span><span class="p">,</span>
            <span class="k">lambda</span><span class="p">:</span> <span class="n">axes</span><span class="o">.</span><span class="n">i2gp</span><span class="p">(</span><span class="n">x_tracker</span><span class="o">.</span><span class="n">get_value</span><span class="p">(),</span> <span class="n">parabola</span><span class="p">)</span>
        <span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">x_tracker</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">set_value</span><span class="p">(</span><span class="mi">4</span><span class="p">),</span> <span class="n">run_time</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">x_tracker</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">set_value</span><span class="p">(</span><span class="o">-</span><span class="mi">2</span><span class="p">),</span> <span class="n">run_time</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
</pre></div>
</div>
</div></div>
<div class="section" id="surfaceexample">
<h2>SurfaceExample<a class="headerlink" href="#surfaceexample" title="Permalink to this headline">¶</a></h2>
<div class="manim-example"><video autoplay="" class="manim-video" controls="" id="surfaceexample" loop="" src="../_static/example_scenes/SurfaceExample.mp4"></video><h5 class="example-header">SurfaceExample<a class="headerlink" href="#surfaceexample">¶</a></h5><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">SurfaceExample</span><span class="p">(</span><span class="n">Scene</span><span class="p">):</span>
    <span class="n">CONFIG</span> <span class="o">=</span> <span class="p">{</span>
        <span class="s2">"camera_class"</span><span class="p">:</span> <span class="n">ThreeDCamera</span><span class="p">,</span>
    <span class="p">}</span>

    <span class="k">def</span> <span class="nf">construct</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">surface_text</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span><span class="s2">"For 3d scenes, try using surfaces"</span><span class="p">)</span>
        <span class="n">surface_text</span><span class="o">.</span><span class="n">fix_in_frame</span><span class="p">()</span>
        <span class="n">surface_text</span><span class="o">.</span><span class="n">to_edge</span><span class="p">(</span><span class="n">UP</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">surface_text</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">(</span><span class="mf">0.1</span><span class="p">)</span>

        <span class="n">torus1</span> <span class="o">=</span> <span class="n">Torus</span><span class="p">(</span><span class="n">r1</span><span class="o">=</span><span class="mi">1</span><span class="p">,</span> <span class="n">r2</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">torus2</span> <span class="o">=</span> <span class="n">Torus</span><span class="p">(</span><span class="n">r1</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">r2</span><span class="o">=</span><span class="mi">1</span><span class="p">)</span>
        <span class="n">sphere</span> <span class="o">=</span> <span class="n">Sphere</span><span class="p">(</span><span class="n">radius</span><span class="o">=</span><span class="mi">3</span><span class="p">,</span> <span class="n">resolution</span><span class="o">=</span><span class="n">torus1</span><span class="o">.</span><span class="n">resolution</span><span class="p">)</span>
        <span class="c1"># You can texture a surface with up to two images, which will</span>
        <span class="c1"># be interpreted as the side towards the light, and away from</span>
        <span class="c1"># the light.  These can be either urls, or paths to a local file</span>
        <span class="c1"># in whatever you've set as the image directory in</span>
        <span class="c1"># the custom_config.yml file</span>

        <span class="c1"># day_texture = "EarthTextureMap"</span>
        <span class="c1"># night_texture = "NightEarthTextureMap"</span>
        <span class="n">day_texture</span> <span class="o">=</span> <span class="s2">"https://upload.wikimedia.org/wikipedia/commons/thumb/4/4d/Whole_world_-_land_and_oceans.jpg/1280px-Whole_world_-_land_and_oceans.jpg"</span>
        <span class="n">night_texture</span> <span class="o">=</span> <span class="s2">"https://upload.wikimedia.org/wikipedia/commons/thumb/b/ba/The_earth_at_night.jpg/1280px-The_earth_at_night.jpg"</span>

        <span class="n">surfaces</span> <span class="o">=</span> <span class="p">[</span>
            <span class="n">TexturedSurface</span><span class="p">(</span><span class="n">surface</span><span class="p">,</span> <span class="n">day_texture</span><span class="p">,</span> <span class="n">night_texture</span><span class="p">)</span>
            <span class="k">for</span> <span class="n">surface</span> <span class="ow">in</span> <span class="p">[</span><span class="n">sphere</span><span class="p">,</span> <span class="n">torus1</span><span class="p">,</span> <span class="n">torus2</span><span class="p">]</span>
        <span class="p">]</span>

        <span class="k">for</span> <span class="n">mob</span> <span class="ow">in</span> <span class="n">surfaces</span><span class="p">:</span>
            <span class="n">mob</span><span class="o">.</span><span class="n">shift</span><span class="p">(</span><span class="n">IN</span><span class="p">)</span>
            <span class="n">mob</span><span class="o">.</span><span class="n">mesh</span> <span class="o">=</span> <span class="n">SurfaceMesh</span><span class="p">(</span><span class="n">mob</span><span class="p">)</span>
            <span class="n">mob</span><span class="o">.</span><span class="n">mesh</span><span class="o">.</span><span class="n">set_stroke</span><span class="p">(</span><span class="n">BLUE</span><span class="p">,</span> <span class="mi">1</span><span class="p">,</span> <span class="n">opacity</span><span class="o">=</span><span class="mf">0.5</span><span class="p">)</span>

        <span class="c1"># Set perspective</span>
        <span class="n">frame</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">camera</span><span class="o">.</span><span class="n">frame</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">set_euler_angles</span><span class="p">(</span>
            <span class="n">theta</span><span class="o">=-</span><span class="mi">30</span> <span class="o">*</span> <span class="n">DEGREES</span><span class="p">,</span>
            <span class="n">phi</span><span class="o">=</span><span class="mi">70</span> <span class="o">*</span> <span class="n">DEGREES</span><span class="p">,</span>
        <span class="p">)</span>

        <span class="n">surface</span> <span class="o">=</span> <span class="n">surfaces</span><span class="p">[</span><span class="mi">0</span><span class="p">]</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">FadeIn</span><span class="p">(</span><span class="n">surface</span><span class="p">),</span>
            <span class="n">ShowCreation</span><span class="p">(</span><span class="n">surface</span><span class="o">.</span><span class="n">mesh</span><span class="p">,</span> <span class="n">lag_ratio</span><span class="o">=</span><span class="mf">0.01</span><span class="p">,</span> <span class="n">run_time</span><span class="o">=</span><span class="mi">3</span><span class="p">),</span>
        <span class="p">)</span>
        <span class="k">for</span> <span class="n">mob</span> <span class="ow">in</span> <span class="n">surfaces</span><span class="p">:</span>
            <span class="n">mob</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">mob</span><span class="o">.</span><span class="n">mesh</span><span class="p">)</span>
        <span class="n">surface</span><span class="o">.</span><span class="n">save_state</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">Rotate</span><span class="p">(</span><span class="n">surface</span><span class="p">,</span> <span class="n">PI</span> <span class="o">/</span> <span class="mi">2</span><span class="p">),</span> <span class="n">run_time</span><span class="o">=</span><span class="mi">2</span><span class="p">)</span>
        <span class="k">for</span> <span class="n">mob</span> <span class="ow">in</span> <span class="n">surfaces</span><span class="p">[</span><span class="mi">1</span><span class="p">:]:</span>
            <span class="n">mob</span><span class="o">.</span><span class="n">rotate</span><span class="p">(</span><span class="n">PI</span> <span class="o">/</span> <span class="mi">2</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">Transform</span><span class="p">(</span><span class="n">surface</span><span class="p">,</span> <span class="n">surfaces</span><span class="p">[</span><span class="mi">1</span><span class="p">]),</span>
            <span class="n">run_time</span><span class="o">=</span><span class="mi">3</span>
        <span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">Transform</span><span class="p">(</span><span class="n">surface</span><span class="p">,</span> <span class="n">surfaces</span><span class="p">[</span><span class="mi">2</span><span class="p">]),</span>
            <span class="c1"># Move camera frame during the transition</span>
            <span class="n">frame</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">increment_phi</span><span class="p">(</span><span class="o">-</span><span class="mi">10</span> <span class="o">*</span> <span class="n">DEGREES</span><span class="p">),</span>
            <span class="n">frame</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">increment_theta</span><span class="p">(</span><span class="o">-</span><span class="mi">20</span> <span class="o">*</span> <span class="n">DEGREES</span><span class="p">),</span>
            <span class="n">run_time</span><span class="o">=</span><span class="mi">3</span>
        <span class="p">)</span>
        <span class="c1"># Add ambient rotation</span>
        <span class="n">frame</span><span class="o">.</span><span class="n">add_updater</span><span class="p">(</span><span class="k">lambda</span> <span class="n">m</span><span class="p">,</span> <span class="n">dt</span><span class="p">:</span> <span class="n">m</span><span class="o">.</span><span class="n">increment_theta</span><span class="p">(</span><span class="o">-</span><span class="mf">0.1</span> <span class="o">*</span> <span class="n">dt</span><span class="p">))</span>

        <span class="c1"># Play around with where the light is</span>
        <span class="n">light_text</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span><span class="s2">"You can move around the light source"</span><span class="p">)</span>
        <span class="n">light_text</span><span class="o">.</span><span class="n">move_to</span><span class="p">(</span><span class="n">surface_text</span><span class="p">)</span>
        <span class="n">light_text</span><span class="o">.</span><span class="n">fix_in_frame</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">FadeTransform</span><span class="p">(</span><span class="n">surface_text</span><span class="p">,</span> <span class="n">light_text</span><span class="p">))</span>
        <span class="n">light</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">camera</span><span class="o">.</span><span class="n">light_source</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">light</span><span class="p">)</span>
        <span class="n">light</span><span class="o">.</span><span class="n">save_state</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">light</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">move_to</span><span class="p">(</span><span class="mi">3</span> <span class="o">*</span> <span class="n">IN</span><span class="p">),</span> <span class="n">run_time</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">light</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">shift</span><span class="p">(</span><span class="mi">10</span> <span class="o">*</span> <span class="n">OUT</span><span class="p">),</span> <span class="n">run_time</span><span class="o">=</span><span class="mi">5</span><span class="p">)</span>

        <span class="n">drag_text</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span><span class="s2">"Try moving the mouse while pressing d or s"</span><span class="p">)</span>
        <span class="n">drag_text</span><span class="o">.</span><span class="n">move_to</span><span class="p">(</span><span class="n">light_text</span><span class="p">)</span>
        <span class="n">drag_text</span><span class="o">.</span><span class="n">fix_in_frame</span><span class="p">()</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">FadeTransform</span><span class="p">(</span><span class="n">light_text</span><span class="p">,</span> <span class="n">drag_text</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
</pre></div>
</div>
</div><p>This scene shows an example of using a three-dimensional surface, and
the related usage has been briefly described in the notes.</p>
<ul class="simple">
<li><p><code class="docutils literal notranslate"><span class="pre">.fix_in_frame()</span></code> makes the object not change with the view angle of the screen, and is always displayed at a fixed position on the screen.</p></li>
</ul>
</div>
<div class="section" id="openingmanimexample">
<h2>OpeningManimExample<a class="headerlink" href="#openingmanimexample" title="Permalink to this headline">¶</a></h2>
<div class="manim-example"><video autoplay="" class="manim-video" controls="" id="openingmanimexample" loop="" src="../_static/example_scenes/OpeningManimExample.mp4"></video><h5 class="example-header">OpeningManimExample<a class="headerlink" href="#openingmanimexample">¶</a></h5><div class="highlight-python notranslate"><div class="highlight"><pre><span></span><span class="k">class</span> <span class="nc">OpeningManimExample</span><span class="p">(</span><span class="n">Scene</span><span class="p">):</span>
    <span class="k">def</span> <span class="nf">construct</span><span class="p">(</span><span class="bp">self</span><span class="p">):</span>
        <span class="n">intro_words</span> <span class="o">=</span> <span class="n">Text</span><span class="p">(</span><span class="s2">"""</span>
<span class="s2">            The original motivation for manim was to</span>
<span class="s2">            better illustrate mathematical functions</span>
<span class="s2">            as transformations.</span>
<span class="s2">        """</span><span class="p">)</span>
        <span class="n">intro_words</span><span class="o">.</span><span class="n">to_edge</span><span class="p">(</span><span class="n">UP</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">Write</span><span class="p">(</span><span class="n">intro_words</span><span class="p">))</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>

        <span class="c1"># Linear transform</span>
        <span class="n">grid</span> <span class="o">=</span> <span class="n">NumberPlane</span><span class="p">((</span><span class="o">-</span><span class="mi">10</span><span class="p">,</span> <span class="mi">10</span><span class="p">),</span> <span class="p">(</span><span class="o">-</span><span class="mi">5</span><span class="p">,</span> <span class="mi">5</span><span class="p">))</span>
        <span class="n">matrix</span> <span class="o">=</span> <span class="p">[[</span><span class="mi">1</span><span class="p">,</span> <span class="mi">1</span><span class="p">],</span> <span class="p">[</span><span class="mi">0</span><span class="p">,</span> <span class="mi">1</span><span class="p">]]</span>
        <span class="n">linear_transform_words</span> <span class="o">=</span> <span class="n">VGroup</span><span class="p">(</span>
            <span class="n">Text</span><span class="p">(</span><span class="s2">"This is what the matrix"</span><span class="p">),</span>
            <span class="n">IntegerMatrix</span><span class="p">(</span><span class="n">matrix</span><span class="p">,</span> <span class="n">include_background_rectangle</span><span class="o">=</span><span class="kc">True</span><span class="p">),</span>
            <span class="n">Text</span><span class="p">(</span><span class="s2">"looks like"</span><span class="p">)</span>
        <span class="p">)</span>
        <span class="n">linear_transform_words</span><span class="o">.</span><span class="n">arrange</span><span class="p">(</span><span class="n">RIGHT</span><span class="p">)</span>
        <span class="n">linear_transform_words</span><span class="o">.</span><span class="n">to_edge</span><span class="p">(</span><span class="n">UP</span><span class="p">)</span>
        <span class="n">linear_transform_words</span><span class="o">.</span><span class="n">set_stroke</span><span class="p">(</span><span class="n">BLACK</span><span class="p">,</span> <span class="mi">10</span><span class="p">,</span> <span class="n">background</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">ShowCreation</span><span class="p">(</span><span class="n">grid</span><span class="p">),</span>
            <span class="n">FadeTransform</span><span class="p">(</span><span class="n">intro_words</span><span class="p">,</span> <span class="n">linear_transform_words</span><span class="p">)</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span><span class="n">grid</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">apply_matrix</span><span class="p">(</span><span class="n">matrix</span><span class="p">),</span> <span class="n">run_time</span><span class="o">=</span><span class="mi">3</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>

        <span class="c1"># Complex map</span>
        <span class="n">c_grid</span> <span class="o">=</span> <span class="n">ComplexPlane</span><span class="p">()</span>
        <span class="n">moving_c_grid</span> <span class="o">=</span> <span class="n">c_grid</span><span class="o">.</span><span class="n">copy</span><span class="p">()</span>
        <span class="n">moving_c_grid</span><span class="o">.</span><span class="n">prepare_for_nonlinear_transform</span><span class="p">()</span>
        <span class="n">c_grid</span><span class="o">.</span><span class="n">set_stroke</span><span class="p">(</span><span class="n">BLUE_E</span><span class="p">,</span> <span class="mi">1</span><span class="p">)</span>
        <span class="n">c_grid</span><span class="o">.</span><span class="n">add_coordinate_labels</span><span class="p">(</span><span class="n">font_size</span><span class="o">=</span><span class="mi">24</span><span class="p">)</span>
        <span class="n">complex_map_words</span> <span class="o">=</span> <span class="n">TexText</span><span class="p">(</span><span class="s2">"""</span>
<span class="s2">            Or thinking of the plane as $</span><span class="se">\\</span><span class="s2">mathds</span><span class="si">{C}</span><span class="s2">$,</span><span class="se">\\\\</span><span class="s2"></span>
<span class="s2">            this is the map $z </span><span class="se">\\</span><span class="s2">rightarrow z^2$</span>
<span class="s2">        """</span><span class="p">)</span>
        <span class="n">complex_map_words</span><span class="o">.</span><span class="n">to_corner</span><span class="p">(</span><span class="n">UR</span><span class="p">)</span>
        <span class="n">complex_map_words</span><span class="o">.</span><span class="n">set_stroke</span><span class="p">(</span><span class="n">BLACK</span><span class="p">,</span> <span class="mi">5</span><span class="p">,</span> <span class="n">background</span><span class="o">=</span><span class="kc">True</span><span class="p">)</span>

        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">FadeOut</span><span class="p">(</span><span class="n">grid</span><span class="p">),</span>
            <span class="n">Write</span><span class="p">(</span><span class="n">c_grid</span><span class="p">,</span> <span class="n">run_time</span><span class="o">=</span><span class="mi">3</span><span class="p">),</span>
            <span class="n">FadeIn</span><span class="p">(</span><span class="n">moving_c_grid</span><span class="p">),</span>
            <span class="n">FadeTransform</span><span class="p">(</span><span class="n">linear_transform_words</span><span class="p">,</span> <span class="n">complex_map_words</span><span class="p">),</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">()</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">play</span><span class="p">(</span>
            <span class="n">moving_c_grid</span><span class="o">.</span><span class="n">animate</span><span class="o">.</span><span class="n">apply_complex_function</span><span class="p">(</span><span class="k">lambda</span> <span class="n">z</span><span class="p">:</span> <span class="n">z</span><span class="o">**</span><span class="mi">2</span><span class="p">),</span>
            <span class="n">run_time</span><span class="o">=</span><span class="mi">6</span><span class="p">,</span>
        <span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">wait</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
</pre></div>
</div>
</div><p>This scene is a comprehensive application of a two-dimensional scene.</p>
<p>After seeing these scenes, you have already understood part of the
usage of manim. For more examples, see <a class="reference external" href="https://github.com/3b1b/videos">the video code of 3b1b</a>.</p>
</div>
</div>

      </article>
      <footer>
        
        <div class="related-pages">
          <a class="next-page" href="config.html">
              <div class="page-info">
                <div class="context">
                  <span>Next</span>
                </div>
                <div class="title">CONFIG dictionary</div>
              </div>
              <svg><use href="#svg-arrow-right"></use></svg>
            </a>
          <a class="prev-page" href="configuration.html">
              <svg><use href="#svg-arrow-right"></use></svg>
              <div class="page-info">
                <div class="context">
                  <span>Previous</span>
                </div>
                
                <div class="title">CLI flags and configuration</div>
                
              </div>
            </a>
        </div>

        <div class="related-information">
              Copyright &#169; - This document has been placed in the public domain.
            |
            Built with <a href="https://www.sphinx-doc.org/">Sphinx</a>
              and
              <a class="muted-link" href="https://pradyunsg.me">@pradyunsg</a>'s
              <a href="https://github.com/pradyunsg/furo">Furo theme</a>.
            |
            <a class="muted-link" href="../_sources/getting_started/example_scenes.rst.txt"
               rel="nofollow">
              Show Source
            </a>
        </div>
        
      </footer>
    </div>
    <aside class="toc-drawer">
      
      
      <div class="toc-sticky toc-scroll">
        <div class="toc-title-container">
          <span class="toc-title">
            Contents
          </span>
        </div>
        <div class="toc-tree-container">
          <div class="toc-tree">
            <ul>
<li><a class="reference internal" href="#">Example Scenes</a><ul>
<li><a class="reference internal" href="#interactivedevlopment">InteractiveDevlopment</a></li>
<li><a class="reference internal" href="#animatingmethods">AnimatingMethods</a></li>
<li><a class="reference internal" href="#textexample">TextExample</a></li>
<li><a class="reference internal" href="#textransformexample">TexTransformExample</a></li>
<li><a class="reference internal" href="#updatersexample">UpdatersExample</a></li>
<li><a class="reference internal" href="#coordinatesystemexample">CoordinateSystemExample</a></li>
<li><a class="reference internal" href="#graphexample">GraphExample</a></li>
<li><a class="reference internal" href="#surfaceexample">SurfaceExample</a></li>
<li><a class="reference internal" href="#openingmanimexample">OpeningManimExample</a></li>
</ul>
</li>
</ul>

          </div>
        </div>
      </div>
      
      
    </aside>
  </main>
</div>
  </body>
</html>